package com.yzkj.siot.controller;

import com.yzkj.siot.annotation.Permission;
import com.yzkj.siot.annotation.WebLog;
import com.yzkj.siot.base.BaseController;
import com.yzkj.siot.cache.SysSettingCache;
import com.yzkj.siot.domain.AdminSetting;
import com.yzkj.siot.service.AdminSettingService;
import com.yzkj.siot.type.ApiType;
import com.yzkj.siot.type.PermissionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统设置
 * 前端控制器
 * </p>
 *
 * @author skye
 * @since 2021-11-07
 */
@RestController
@RequestMapping("/setting")
public class SettingController extends BaseController {

    @Autowired
    AdminSettingService service;

    @WebLog(type = ApiType.UPDATE)
    @Permission(type = PermissionType.ADMIN)
    @PostMapping("update")
    public AdminSetting update(@RequestBody AdminSetting entity) {
        entity.setId(1);
        SysSettingCache.setting = entity;
        this.service.updateById(entity);
        return this.service.getById(1);
    }

    @WebLog(type = ApiType.READ)
    @Permission(type = PermissionType.ADMIN)
    @GetMapping("queryOne")
    public AdminSetting queryOne() {

        return this.service.getById(1);
    }
}

